import {createRes} from './utils';
const controllers = require.context('./controller', true, /\.ts$/);
const localHttp = function(options){
	return new Promise(function(resolve,reject){
		let isOk = false;
		controllers.keys().forEach(key=>{
			let item = controllers(key).default||controllers(key);
			if(options.url === item.route){
				isOk = true;
				item.handle(options.data).then(res=>{
					resolve(res)
				},res=>{
					resolve(res)
				})
			}
		})
		!isOk && resolve(createRes('未匹配到接口：'+options.url));
	})
}
export default localHttp;